<template>
  <PiTable :tableData :tableColumns :pagination="page" @pageChange="pageChange">
    <template #icon>
      <el-icon><Setting /></el-icon>
    </template>
    <!--<template #name="{ row }">-->
    <!--  <el-link-->
    <!--    type="primary"-->
    <!--    v-jump.open="['projectDetail', { oid: row.oid, title: `${row.name}，${row.projectName}` }]"-->
    <!--  >-->
    <!--    {{ row.name }}-->
    <!--  </el-link>-->
    <!--</template>-->
  </PiTable>
</template>

<script setup>
const route = useRoute();
const loading = ref(false);
const tableColumns = ref([]);
const tableData = ref([]);
const page = reactive({
  pageNum: 1, //当前页
  pageSize: 10, //每页数
  total: 0, //数据总量
});

onMounted(() => {
  getData();
});

/**
 * 获取表格数据
 * */
const getData = () => {
  loading.value = true;
  const params = {
    tableID: 'ProjectChangeRequestTable',
    oid: route.query.oid,
    page: page.pageNum,
    range: page.pageSize,
  };

  window.$api.projectListApi
    .findChangeRequests(params)
    .then((res) => {
      tableColumns.value = [
        {
          prop: 'icon',
          label: '',
          width: 40,
        },
        ...res.data.columns.map((item) => ({ ...item, sortable: true })),
      ];
      tableData.value = res.data.rows;
      page.total = res.data.total;
    })
    .finally(() => {
      loading.value = false;
    });
};
/**
 * 分页
 * @pageNum {number} 当前页码
 * @pageSize {number} 每页显示数
 * */
const pageChange = (pageNum, pageSize) => {
  page.pageNum = pageNum;
  page.pageSize = pageSize;
  getData();
};
</script>

<style scoped lang="less"></style>
